import java.util.Scanner;

public class Solution {
    public int removeDuplicates(int[] nums){
        int n = nums.length;
        if(n == 0){
            return 0;
        }
        int fast = 1;
        int slow = 1;
        while(fast < n){
            if(nums[fast] != nums[fast-1]){
                nums[slow] = nums[fast];
                slow++;
            }
            fast++;
        }
        return slow;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNextInt()) {
            int size = scanner.nextInt();
            int[] nums = new int[size];
            for (int i = 0; i < nums.length; i++) {
                nums[i] = scanner.nextInt();
            }
            Solution solution = new Solution();
            int newNums = solution.removeDuplicates(nums);
            System.out.println(newNums);
            for (int i = 0; i < newNums; i++) {
                System.out.print(nums[i]+" ");
            }
        }
    }
}
